import type { AiTimelineEntry, AiTimelineKind } from '../stores/aiTimeline'
import type * as monaco from 'monaco-editor'

export interface DiffModels {
  original: monaco.editor.ITextModel
  modified: monaco.editor.ITextModel
}

export interface AiStatus {
  hasChanges: boolean
  latestEntry?: AiTimelineEntry | null
  totalChanges: number
  kind?: AiTimelineKind
  tool?: string
  timestamp?: number
}

export interface SystemHistoryDiff {
  source: string
  id: string
  originalContent: string
  resourceUri: string
}

export interface EditorTab {
  id: string
  title: string
  ext?: string
  path?: string
  dirty?: boolean
  content?: string
  savedContent?: string
  preview?: boolean
  aiStatus?: AiStatus | null
  showingDiff?: boolean
  /** Whether to render diff side by side (true) or inline (false) */
  diffSideBySide?: boolean
  /** Temporary flag to indicate just switched to diff mode, used to control auto-selection behavior */
  justSwitchedToDiff?: boolean
  diffModels?: DiffModels | null
  autoDiffEntryId?: string | null
  /** Disposable for diff model content change tracking (tab-scoped) */
  _diffContentDisposable?: monaco.IDisposable | null
  /** original editor instance when switching to diff (optional) */
  originalEditor?: monaco.editor.IStandaloneCodeEditor | monaco.editor.IStandaloneDiffEditor | null
  /** Whether current diff is aggregated from multiple AI timeline entries */
  aggregatedDiff?: boolean
  /** Number of entries aggregated in current diff view */
  diffEntryCount?: number
  /** System history diff data for timeline diff functionality */
  systemHistoryDiff?: SystemHistoryDiff | null
  /** When updated, forces MonacoEditor remount via :key */
  editorRerenderKey?: string
  /** Timeline tab specific properties */
  isTimelineTab?: boolean
  timelineData?: TimelineTabData | null
}

export interface TimelineTabData {
  /** Source file path for the timeline comparison */
  sourceFilePath: string
  /** Timeline item ID being compared */
  timelineItemId: string
  /** Timeline source (git, local-history, etc.) */
  timelineSource: string
  /** Timestamp of the timeline item */
  timestamp: number
  /** Original content from timeline */
  originalContent: string
  /** Current content for comparison */
  currentContent: string
}

export type LayoutGroupNode = {
  id: string
  type: 'group'
  tabs: EditorTab[]
  activeId: string | null
}

export type LayoutSplitNode = {
  id: string
  type: 'split'
  direction: 'row' | 'col'
  sizes: number[]
  children: LayoutNode[]
}

export type LayoutNode = LayoutGroupNode | LayoutSplitNode

export type GroupMode = 'editor' | 'diff'